package com.cdu.guoxinan.www.smartcom.service.impl;

import com.cdu.guoxinan.www.smartcom.domian.dto.PropertyQueryDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Property;
import com.cdu.guoxinan.www.smartcom.domian.vo.PropertyVO;
import com.cdu.guoxinan.www.smartcom.mapper.PropertyMapper;
import com.cdu.guoxinan.www.smartcom.service.PropertyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PropertyServiceImpl implements PropertyService {
    @Resource
    private PropertyMapper propertyMapper;

    @Override
    public PageInfo<PropertyVO> queryPage(PropertyQueryDTO propertyQueryDTO) {
        PageHelper.startPage(propertyQueryDTO.getPage(),propertyQueryDTO.getLimit());
        List<PropertyVO> list = propertyMapper.queryPage(propertyQueryDTO);
        PageInfo<PropertyVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Boolean add(Property property) {
        int result = propertyMapper.add(property);
        return result > 0;
    }

    @Override
    public boolean update(Property property) {
        int result = propertyMapper.update(property);
        return result > 0;
    }

    @Override
    public boolean delete(Integer id) {
        int result = propertyMapper.delete(id);
        return result > 0;
    }
    
    @Override
    public List<Property> getUserProperties(Long userId) {
        return propertyMapper.selectPropertiesByUserId(userId);
    }
}
